<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="../../configure.js"></script>
</head>
<body style="background-color: #F5F6F7">
<div class="container" style="background-color:white;margin-top: 20px">
    <form id="form"    style="margin:10px 0px 10px">
        <span style="font-size:larger;color: black">添加用户</span>
        <hr style="border: black 1px solid">
        <!-- <div class="form-group">
            <label for="userId">用户ID</label>
            <input type="text" class="form-control" name="userId" id="userId" placeholder="请输入用户ID">
        </div> -->
        <div class="form-group">
            <label for="userName">用户姓名</label>
            <input type="text" class="form-control" name="userName" id="userName" placeholder="请输入用户姓名">
        </div>
        <div class="form-group">
            <label for="userPassword">用户密码</label>
            <input type="password" class="form-control" name="userPassword" id="userPassword">
        </div>
        <div class="form-group">
            <label>性别 :</label>
            <label class="radio-inline">
                <input type="radio" name="sex" value="1">男
            </label>
            <label class="radio-inline">
                <input type="radio" name="sex" value="0">女
            </label>
        </div>
        <div class="form-group">
            <label for="age">年龄</label>
            <input type="text" class="form-control" name="age" id="age" placeholder="请输入年龄">
        </div>
        <div class="form-group">
            <label for="userPhone">电话号</label>
            <input type="text" class="form-control" name="userPhone" id="userPhone" placeholder="请输入电话号">
        </div>
        <div class="form-group">
            <label for="IdCard">身份证号</label>
            <input type="text" class="form-control" name="idCard" id="IdCard" placeholder="请输入身份证号">
        </div>
        <div class="form-group">
            <label for="address">详细地址</label>
            <input type="text" class="form-control" name="address" id="address" placeholder="请输入详细地址">
        </div>

        <button type="submit" class="btn btn-primary form-control ">添加</button>
    </form>
</div>
</body>
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/distpicker.data.js"></script>
<script src="../js/distpicker.js"></script>
<script src="../layer/layer.js"></script>
<script type="text/javascript">
    $(function(){
        $("#form").submit(function(){
            let userPhone = $("#userPhone").val();
            let userName = $("#userName").val();
            let IdCard = $("#IdCard").val();
            let age = $("#age").val();
            let password = $("#userPassword").val();
            let passwordReg = /^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$/;
            if (userName=="") {
                layer.msg("姓名不能为空");
                return false
            }
            if (password=="") {
                layer.msg("密码不能为空");
                if(!passwordReg.test(password))
                return false
            }
            
            if (age=="") {
                layer.msg("年龄不能为空");
                return false
            }
            
            let ageReg = /(^\d{n}$)/ ;
            if (!ageReg.test(age)) {
                    layer.msg("年龄必须为数字");
                    return false
                }
            if (userPhone=="") {
                layer.msg("手机号码不能为空");
                return false
            }else{
                if (!phoneReg.test(userPhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }
            
            if (IdCard=="") {
                layer.msg("身份证号不能为空");
                return false
            }
            
            $.post(url+"/admin/addUser",{
                userId:userId,
                userName:userName,
                userPassword:userPassword,
                idCard:idCard,
                address:address
            },function(data){
                //layer.msg(data.data.message);
                console.log(data)
                if(data.code == 1){
                    //录入成功
                    layer.msg("添加失败");
                    $("input").val("");
                    // $("input:eq(1)").val("顺丰速运");
                }else{
                    layer.msg("添加成功");
                    //录入失败
                }
            });
            return false
        });
    });
</script>
</html>